extends Node2D
@onready var wave_timer: Timer = $WaveTimer
@onready var enemy_timer: Timer = $EnemyTimer
@onready var path_2d: Path2D = $Path2D
@onready var cash_label: Label = $GUI/CashLabel
@onready var cash_label_2: Label = $GUI/CashLabel2
@onready var cash_label_3: Label = $GUI/CashLabel3
@onready var cash_label_4: Label = $GUI/CashLabel4

var mob = preload("res://enemy.tscn")
var tower = preload("res://Tower.tscn")
var money = 25
var wave = 0
var mobs_left = 0
var wave_mobs = [5,6,10,20,40,0]
var wave_speed = [1,1,0.5,0.5,0.3,100]
var instance
var building = false
func _ready() -> void:
	wave_timer.start()
	
func _process(delta):
	cash_label.text = "Cash: " + str(money)	
	cash_label_2.text = "Wave:" + str(wave)
	cash_label_4.text = "Mobs Left:" +str(mobs_left)

func tower_built():
	building = false
	money -= 25
	
func _on_wave_timer_timeout() -> void:
	mobs_left = wave_mobs[wave] # Replace with function body.
	enemy_timer.wait_time  = wave_speed[wave]
	enemy_timer.start()


func _on_enemy_timer_timeout() -> void:
	instance = mob.instantiate()
	path_2d.add_child(instance)
	mobs_left -= 1
	if mobs_left <= 0:
		enemy_timer.stop()
		wave +=1
		if wave < len(wave_mobs)-1:
			wave_timer.start()
		elif mobs_left == 0:
			cash_label_3.text = "you win"


func _on_button_pressed() -> void:
	if building == false and money >= 25:
		instance = tower.instantiate()
		add_child(instance)
		building = true
